home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 June: Reference Library / Dev.CD Jun 99 RL Disk 1.toast / What's New / Development Kits / Mac_OS_USB_DDK_v1.2 / Examples / USBTabletModule / USBTabletModuleHeader.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-04-15  |  5.8 KB  |  202 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        USBTabletModuleHeader.c
  3.  
  4.     Contains:    USBTabletModule Header file
  5.  
  6.     Version:    xxx put version here xxx
  7.  
  8.     Copyright:    © 1997-1998 by Apple Computer, Inc., all rights reserved.
  9.  
  10. */
  11.  
  12. #include <Types.h>
  13. #include <Devices.h>
  14. #include <DriverServices.h>
  15. #include <USB.h>
  16.  
  17.  
  18. #include "USBTabletModule.h"
  19. #include "USBTabletModuleVersion.h"
  20.  
  21. extern    usbWacomPBStruct myWacomPB;
  22.  
  23. //------------------------------------------------------
  24. //
  25. //    This is the driver description structure that the expert looks for first.
  26. //  If it's here, the information within is used to match the driver
  27. //  to the device whose descriptor was passed to the expert.
  28. //    Information in this block is also used by the expert when an
  29. //  entry is created in the Name Registry.
  30. //
  31. //------------------------------------------------------
  32. USBDriverDescription    TheUSBDriverDescription = 
  33. {
  34.     // Signature info
  35.     kTheUSBDriverDescriptionSignature,
  36.     kInitialUSBDriverDescriptor,
  37.     
  38.     // Device Info
  39.     0x056a,                                    // vendor = not device specific
  40.     0,                                        // product = not device specific
  41.     0,                                        // version of product = not device specific
  42.     kUSBMouseInterfaceProtocol,                // protocol = not device specific
  43.     
  44.     // Interface Info    (* I don't think this would always be required...*)                
  45.     0,                                        // Configuration Value
  46.     0,                                        // Interface Number
  47.     kUSBHIDInterfaceClass,                    // Interface Class
  48.     kUSBBootInterfaceSubClass,                 // Interface SubClass
  49.     kUSBMouseInterfaceProtocol,                // Interface Protocol
  50.         
  51.     
  52.     // Driver Info
  53.     "\pUSBHIDWacomModule",                        // Driver name for Name Registry
  54.     kUSBHIDInterfaceClass,                    // Device Class  (from USBDeviceDefines.h)
  55.     kUSBBootInterfaceSubClass,                // Device Subclass 
  56.     kWacomHexMajorVers, 
  57.     kWacomHexMinorVers, 
  58.     kWacomCurrentRelease, 
  59.     kWacomReleaseStage,                        // version of driver  
  60.     
  61.     // Driver Loading Info
  62.     kUSBProtocolMustMatch+kUSBDoNotMatchInterface+kUSBDoNotMatchGenericDevice                    // Flags (currently undefined)
  63. };
  64.  
  65. USBClassDriverPluginDispatchTable TheClassDriverPluginDispatchTable =
  66. {
  67.     kClassDriverPluginVersion,                // Version of this structure
  68.     WacomDriverValidateHW,                    // Hardware Validation Procedure
  69.     WacomDeviceInitialize,                    // Initialization Procedure
  70.     WacomInterfaceInitialize,                // Interface Initialization Procedure
  71.     WacomDriverFinalize,                    // Finalization Procedure
  72.     WacomDriverNotifyProc,                    // Driver Notification Procedure
  73. };
  74.     
  75.  
  76. // Hardware Validation
  77. // Called upon load by Expert
  78. OSStatus WacomDriverValidateHW(USBDeviceRef device, USBDeviceDescriptor *desc)
  79. {
  80. #pragma unused (device)
  81. #pragma unused (desc)
  82.  
  83.     return (OSStatus)kUSBNoErr;
  84. }
  85.  
  86.  
  87. // Initialization function
  88. // Called upon load by Expert
  89. OSStatus     WacomDeviceInitialize (USBDeviceRef device, USBDeviceDescriptorPtr pDesc,  UInt32 busPowerAvailable)
  90. {
  91. #pragma unused (busPowerAvailable)
  92.  
  93.     //DebugStr("\pIn Wacom Driver");
  94.     // until we get going, it's okay to accept a call to finalize
  95.     DeviceInitialize(device, pDesc, busPowerAvailable);
  96.     return (OSStatus)kUSBNoErr;
  97. }
  98.  
  99.  
  100. // Interface Initialization Initialization function
  101. // Called upon load by Expert
  102. OSStatus     WacomInterfaceInitialize (UInt32 interfacenum, USBInterfaceDescriptorPtr pInterface, USBDeviceDescriptorPtr pDesc, USBDeviceRef device)
  103. {
  104. #pragma unused (interfacenum)
  105. #pragma unused (pInterface)
  106. #pragma unused (pDesc)
  107. #pragma unused (device)
  108.  
  109.     return (OSStatus)noErr;
  110. }
  111.  
  112. // Termination function
  113. // Called by Expert when driver is being shut down
  114. OSStatus WacomDriverFinalize(USBDeviceRef theDeviceRef, USBDeviceDescriptorPtr pDesc)
  115. {
  116. #pragma unused (pDesc)
  117. OSStatus myErr;
  118. //USBHIDData        theWacomData;
  119.  
  120.     USBExpertStatus(theDeviceRef, "\pUSBHIDWacomModule: Finalize", theDeviceRef);
  121.     
  122.     /*
  123.     if (myWacomPB.pSHIMInterruptRoutine)            
  124.     {                                                
  125.         USBExpertStatus(theDeviceRef, "\pUSBHIDWacomModule: Release Wacom buttons", theDeviceRef);
  126.         theWacomData.Wacom.buttons = 0;
  127.         theWacomData.Wacom.XDelta = 1;
  128.         theWacomData.Wacom.YDelta = 1;
  129.         (*myWacomPB.pSHIMInterruptRoutine)(myWacomPB.interruptRefcon, (void *)&theWacomData);
  130.     }
  131.     */
  132.     
  133.     if (myWacomPB.pCursorDeviceInfo != 0)                
  134.     {
  135.         USBExpertStatus(theDeviceRef, "\pUSBHIDWacomModule: Remove CDM device", theDeviceRef);
  136.         CursorDeviceDisposeDevice(myWacomPB.pCursorDeviceInfo);
  137.         myWacomPB.pCursorDeviceInfo = 0;
  138.     }
  139.     
  140.     if (myWacomPB.pipeRef)
  141.     {
  142.         USBExpertStatus(theDeviceRef, "\pUSBHIDWacomModule: Aborting interrupt pipe", theDeviceRef);
  143.         USBAbortPipeByReference(myWacomPB.pipeRef);
  144.     }
  145.     
  146.     myWacomPB.pb.usbReference = theDeviceRef;
  147.     myWacomPB.pb.pbVersion = kUSBCurrentPBVersion;
  148.     myWacomPB.pb.usbFlags = 0;
  149.     myWacomPB.pb.usbRefcon = 0;             
  150.     myWacomPB.pb.usbCompletion = (USBCompletion)-1;
  151.     
  152.     myErr = USBDeallocMem(&myWacomPB.pb);
  153.     
  154.     return (OSStatus)noErr;
  155. }
  156.  
  157. OSStatus    WacomDriverNotifyProc(UInt32     notification, void *pointer, UInt32 refCon)
  158. {
  159. #pragma unused (pointer)
  160. #pragma unused (notification)
  161.     return(kUSBNoErr);
  162. }
  163.  
  164. void DeviceInitialize(USBDeviceRef device, USBDeviceDescriptorPtr pDeviceDescriptor, UInt32 busPowerAvailable)
  165. {
  166. #pragma unused (pDeviceDescriptor)
  167. static Boolean beenThereDoneThat = false;
  168.  
  169.     DebugStr("\pIn Wacom Driver");
  170.     if(beenThereDoneThat)
  171.     {
  172.         USBExpertFatalError(device, kUSBInternalErr, "\pWacom driver is not reentrant!", 0);
  173.         return;
  174.     }
  175.     beenThereDoneThat = true;
  176.     
  177.     InitParamBlock(device, &myWacomPB.pb);
  178.     
  179.     myWacomPB.deviceRef = device;    
  180.     myWacomPB.pSHIMInterruptRoutine = nil;
  181.     myWacomPB.pSavedInterruptRoutine = nil;
  182.  
  183.     myWacomPB.busPowerAvailable = busPowerAvailable;                            
  184.     myWacomPB.transDepth = 0;                            
  185.     myWacomPB.retryCount = kWacomRetryCount;
  186.     
  187.     myWacomPB.deviceRef = device;        
  188.     myWacomPB.interfaceRef = nil;        
  189.     myWacomPB.pipeRef = nil;        
  190.     
  191.     myWacomPB.pb.usbRefcon = kFindInterface;            
  192.     myWacomPB.pb.usbReference = device;
  193.     myWacomPB.pb.pbLength = sizeof(usbWacomPBStruct);
  194.     myWacomPB.unitsPerInch = (Fixed)(400<<16);
  195.     myWacomPB.pCursorDeviceInfo = 0;                
  196.     API_ControlDevice(kHIDEnableDemoMode,0);
  197.  
  198.     InitParamBlock(device, &myWacomPB.pb);
  199.     InitiateTransactionProc(&myWacomPB.pb);
  200. }
  201.  
  202.